import { defineStore } from 'pinia'
import { AwsConfig } from './typing'

interface BaseObject {
  [key: string]: string
}
export interface CompoundObject {
  [key: string]: BaseObject
}
interface Apollo {
  AWS_CONFIG: CompoundObject
  API_CONFIG: BaseObject
  publicKey: string
}
const useSystemStore = defineStore('system', () => {
  const apollo = ref<Apollo>({
    AWS_CONFIG: {},
    API_CONFIG: {},
    publicKey: '',
  })

  function updateAwsConfig(AWS_CONFIG: AwsConfig) {
    apollo.value.AWS_CONFIG = JSON.parse(JSON.stringify(AWS_CONFIG))
  }
  function updateApiCconfig(API_CONFIG: object) {
    apollo.value.API_CONFIG = JSON.parse(JSON.stringify(API_CONFIG))
  }
  function updatePublicKey(publicKey: string) {
    apollo.value.publicKey = publicKey
  }

  return {
    apollo,
    updateAwsConfig,
    updateApiCconfig,
    updatePublicKey,
    API_CONFIG: computed(() => apollo.value.API_CONFIG),
    AWS_CONFIG: computed(() => apollo.value.AWS_CONFIG),
    publicKey: computed(() => apollo.value.publicKey),
  }
})

export default useSystemStore
